package cn.iocoder.yudao.module.erp.controller.admin.giitem.giitembj;

import cn.iocoder.yudao.module.erp.controller.admin.giitem.giitembj.vo.GiItemBjPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.giitem.giitembj.vo.GiItemBjRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.giitem.giitembj.vo.GiItemBjSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.giitem.GiItemBjDO;
import cn.iocoder.yudao.module.erp.service.giitem.GiItemBjService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import java.io.IOException;
import java.util.List;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

@Tag(name = "管理后台 - ERP物流北疆口岸仓库货号详情")
@RestController
@RequestMapping("/erp/gi-item-bj")
@Validated
public class GiItemBjController {

    @Resource
    private GiItemBjService giItemBjService;

    @PostMapping("/create")
    @Operation(summary = "创建ERP物流北疆口岸仓库货号详情")
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-bj:create')")
    public CommonResult<Long> createGiItemBj(@Valid @RequestBody GiItemBjSaveReqVO createReqVO) {
        return success(giItemBjService.createGiItemBj(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新ERP物流北疆口岸仓库货号详情")
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-bj:update')")
    public CommonResult<Boolean> updateGiItemBj(@Valid @RequestBody GiItemBjSaveReqVO updateReqVO) {
        giItemBjService.updateGiItemBj(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除ERP物流北疆口岸仓库货号详情")
    @Parameter(name = "id", description = "编号", required = true)
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-bj:delete')")
    public CommonResult<Boolean> deleteGiItemBj(@RequestParam("id") Long id) {
        giItemBjService.deleteGiItemBj(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得ERP物流北疆口岸仓库货号详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-bj:query')")
    public CommonResult<GiItemBjRespVO> getGiItemBj(@RequestParam("id") Long id) {
        GiItemBjDO giItemBj = giItemBjService.getGiItemBj(id);
        return success(BeanUtils.toBean(giItemBj, GiItemBjRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得ERP物流北疆口岸仓库货号详情分页")
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-bj:query')")
    public CommonResult<PageResult<GiItemBjRespVO>> getGiItemBjPage(@Valid GiItemBjPageReqVO pageReqVO) {
        PageResult<GiItemBjDO> pageResult = giItemBjService.getGiItemBjPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, GiItemBjRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出ERP物流北疆口岸仓库货号详情 Excel")
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-bj:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportGiItemBjExcel(@Valid GiItemBjPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<GiItemBjDO> list = giItemBjService.getGiItemBjPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "ERP物流北疆口岸仓库货号详情.xls", "数据", GiItemBjRespVO.class,
                        BeanUtils.toBean(list, GiItemBjRespVO.class));
    }

}